<template>
	<view class="page">
		<u-navbar title="角色列表" border @leftClick="$utils.back()" placeholder>
		</u-navbar>
		<filter @reload='reload' />
		<view class="body">
			<z-paging ref="paging" style="height: 100%;" :fixed="false" v-model="data" @query="query"
				:default-page-no="1" :default-page-size="10">
				<view v-for="item in data" :key="item.id" class="roleItem">
					<u-text lines='1' :text='item.display_name' size='24rpx' />
					<u-icon name="more-dot-fill" size="30rpx" @click='openSelect(item)'></u-icon>
				</view>
			</z-paging>

		</view>
		<view class="add" @click="jumpAdd">
			<u-icon color='#fff' name='man-add' size='50rpx' />
		</view>
		<root-portal>
			<u-action-sheet :actions="columns" :show="selectShow" @close='selectShow=false' @select="confirm"
				closeOnClickOverlay></u-action-sheet>
			<u-modal :show="delShow" content='是否确认删除？' showCancelButton @confirm='Del'
				@cancel='delShow=false'></u-modal>
		</root-portal>
	</view>
</template>

<script>
	import filter from '@/components_company/filter.vue'
	export default {
		components: {
			filter
		},
		data() {
			return {
				delShow: false,
				data: [],
				loading: true,
				selectItem: null,
				selectShow: false,
				columns: [{
						name: '编辑'
					},
					{
						name: '删除'
					}
				],
				keywords: ''
			}
		},
		methods: {
			reload(e) {
				this.keywords = e.keywords
				this.$refs.paging.reload()
			},
			query(page, size) {
				let obj = {
					keywords: this.keywords,
					page,
					size
				}
				uni.showLoading({
					title: '加载中...'
				})
				this.$api_company.Administrator_role.List(obj).then(res => {
					this.$refs.paging.complete(res.data.data)
					this.loading = false
					uni.hideLoading()
				}).catch(err => {
					uni.$u.toast(err.message)
					uni.hideLoading()
				})
			},
			openSelect(item) {
				this.selectItem = item
				this.selectShow = true
			},
			confirm(e) {
				const item = e.name
				this.selectShow = false
				if (item == '编辑') {
					this.update()
				} else if (item == '删除') {
					this.delShow = true
				}
			},
			Del() {
				this.delShow = false
				uni.showLoading({
					title: '删除中...'
				})
				this.$api_company.Administrator_role.Del(this.selectItem.id).then(res => {
					this.loading = true
					this.$refs.paging.reload()
					uni.hideLoading()
				}).catch(err => {
					uni.$u.toast(err.message)
					uni.hideLoading()
				})
			},
			jumpAdd() {
				this.$utils.navigateTo({
					url: '/administrator_role/add'
				})
			},
			update() {
				this.$utils.navigateTo({
					url: '/administrator_role/update?id=' + this.selectItem.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 0rpx 20rpx;
		height: 100vh;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
		/* 兼容 iOS 设备 */
		padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		background-color: #f5f5f5;
	}

	.body {
		flex: 1;
		margin-top: 20rpx;
	}

	.roleItem {
		background-color: #fff;
		padding: 10rpx;
		border-radius: 8rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.add {
		position: fixed;
		right: 5vw;
		bottom: 20vh;
		border-radius: 100%;
		box-shadow: 0 0 10rpx #ddd;
		background: rgba(0, 0, 0, 0.7);
		padding: 20rpx;

	}
</style>